import java.util.*;
public class DFS {
	public static void main(String[] args) {
		int n;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] boxs = new int[n + 1];
		int[] books = new int[n + 1];
		dfs(books, boxs,1,n);
		}
	public static void dfs(int[]book,int []box,int index,int n) {
		if(index==n+1) {
			for(int i=1;i<=n;i++) {
				System.out.print(box[i]+" ");
			}
			System.out.println();
			return;
		}
		for(int i=1;i<=n;i++) {
			if(book[i]==0) {
				box[index]=i;
				book[i]=1;
				dfs(book,box,index+1,n);
				book[i]=0;
			}
		}
	}
}
